<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	pageContext.setAttribute("basePath",request.getContextPath());
%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <title>用户列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="${basePath }/static/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="${basePath }/static/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- bootstrap-table 表格插件样式 -->
    <link href="${basePath }/static/ajax/libs/bootstrap-table/bootstrap-table.min.css" rel="stylesheet"/>
    <link href="${basePath }/static/css/animate.css" rel="stylesheet"/>
    <link href="${basePath }/static/css/style.css" rel="stylesheet"/>
    <link href="${basePath }/static/ruoyi/css/ry-ui.css" rel="stylesheet"/>
    <link href="${basePath }/static/ajax/libs/jquery-layout/jquery.layout-latest.css" rel="stylesheet"/>
    <link href="${basePath }/static/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" rel="stylesheet"/>
</head>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form" method="POST" action="${basePath }/system/user/search.do">
                    <div class="select-list">
                        <ul>
                            <li>
                                                                                                姓名：<input name="name" type="text"/>
                            </li>
                            <li>
                                                                                     权限：<select name="roleId">
                                    <option value="1">超级管理员</option>
                                    <option value="2">普通管理员</option>
                                    <option value="3">仓库管理员</option>
                                    <option value="4">工作人员</option>
                                    <option value="5">游客</option>
                                </select>
                            </li>
                            <li>
                                                                            用户状态：<select name="status">
	                                <option value="1">正常</option>
	                                <option value="0">冻结</option>
                                </select>
                            </li>
                            <li>
                                <button class="btn btn-primary btn-rounded btn-sm user-search" type="submit">
                                	<i class="fa fa-search"></i>&nbsp;搜索
                                </button>
                                <a class="btn btn-info btn-rounded btn-sm" href="${basePath }/system/user/list.do">
                                	<i class="fa fa-search"></i>&nbsp;搜索所有
                                </a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()">
                                	<i class="fa fa-refresh"></i>&nbsp;重置
                                </a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <div class="bootstrap-table">
                    <div class="fixed-table-container" style="padding-bottom: 0px;">
                        <div class="fixed-table-body">
                            <div class="fixed-table-loading" style="top: 41px; display: none;">正在努力地加载数据中，请稍候……</div>
                            
                            <table id="bootstrap-table" data-mobile-responsive="true" class="table table-hover">
                                <thead>
                                <tr>
                                    <th class="bs-checkbox" style="width: 36px; ">
                                        <div class="th-inner"><input name="btSelectAll" type="checkbox"></div>
                                    </th>
                                    <th>
                                        <div class="th-inner ">用户ID</div>
                                    </th>
                                    <th>
                                        <div class="th-inner">姓名</div>
                                    </th>
                                    <th>
                                        <div class="th-inner ">角色</div>
                                    </th>
                                    <th>
                                        <div class="th-inner ">邮箱</div>
                                    </th>
                                    <th>
                                        <div class="th-inner ">手机</div>
                                    </th>
                                    <th style="text-align: center;">
                                        <div class="th-inner ">用户状态</div>
                                    </th>
                                    <th style="text-align: center;">
                                        <div class="th-inner ">操作</div>
                                    </th>
                                </tr>
                                </thead>

                                <tbody>
                                <c:forEach items="${query.list }" var="user">
                                	
                                	<tr data-index="${user.index }">
	                                    <td class="bs-checkbox ">
	                                        <input data-index="0" name="btSelectItem" type="checkbox">
	                                    </td>
	                                    <td>${user.userId }</td>
	                                    <td>${user.name }</td>
	                                    <td>${user.roleName }</td>
	                                    <td>${user.email }</td>
	                                    <td>${user.phone }</td>
	                                    <td style="text-align: center; ">
	                                    	<c:if test="${user.status == 0}">
	                                    		<span class="label label-danger">冻结</span>
											</c:if>
											<c:if test="${user.status == 1}">
	                                    		<span class="label label-success">正常</span>
											</c:if>
	                                    </td>
	                                    <td style="text-align: center;">
	                                        <a class="btn btn-info btn-xs user_detial" href="javascript:void(0)" data-id="${user.userId }">
	                                            <i class="fa fa-search"></i>查看
	                                        </a>
	                                        <c:if test="${user.roleId != 1 }">
	                                        	<c:if test="${user.roleId != 2 }">
			                                        <c:if test="${user.status == 0 }">
			                                        	<a class="btn btn-danger btn-xs" href="javascript:void(0)"  disabled="disabled">
			                                            	<i class="fa fa-user"></i>冻结
			                                        	</a>
			                                        </c:if>
			                                        <c:if test="${user.status != 0 }">
			                                        	<a class="btn btn-danger btn-xs user_fraze" href="javascript:void(0)" data-id="${user.email }">
			                                            	<i class="fa fa-user"></i>冻结
			                                        	</a>
			                                        </c:if>
		                                        </c:if>
	                                        </c:if>
	                                    </td>
                                	</tr>                                	
                                </c:forEach>
                                
                                </tbody>
                            </table>
                        </div>
                        <div class="fixed-table-pagination" style="display: block;">
                            <div class="pull-left pagination-detail">
                                <span class="pagination-info">第${query.pageNum }页，共${query.pages + 1}页，共  ${query.total } 条记录。</span>
                            </div>
                            <div class="pull-right pagination">
                                <ul class="pagination pagination-outline">
                                    <c:choose>
									    <c:when test="${query.pageNum == 1 }"> 
									   		<li class="page-pre active">
		                                    	<a href="javascript:void(0)">‹</a>
		                                    </li>
									   	</c:when>
									   	<c:otherwise>
									   		<li class="page-pre">
		                                    	<a href="${basePath }/system/user/list.do?pagenum=${query.pageNum - 1 }">‹</a>
		                                    </li>
									   	</c:otherwise>
									</c:choose>
                                    
                                    <c:forEach items="${query.navigateNums }" var="num">
                                    	<c:if test="${query.pageNum == num }">
                                    		<li class="page-number active">
                                    			<a href="javascript:void(0)">${num }</a>
                                    		</li>
                                    	</c:if>
                                    	<c:if test="${query.pageNum != num }">
                                    		<li class="page-number">
                                    			<a href="${basePath }/system/user/list.do?pagenum=${num }">${num }</a>
                                    		</li>
                                    	</c:if>
                                    </c:forEach>
                                    <c:if test="${query.pageNum == query.pages+1 }">
	                                    <li class="page-next active">
	                                    	<a href="javascript:void(0)">›</a>
	                                    </li>
                                    </c:if>
                                    <c:if test="${query.pageNum < query.pages }">
	                                    <li class="page-next">
	                                    	<a href="${basePath }/system/user/list.do?pagenum=${query.pageNum + 1 }">›</a>
	                                    </li>
                                    </c:if>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>

<script src="${basePath }/static/js/jquery.min.js"></script>
<script src="${basePath }/static/js/bootstrap.min.js"></script>
<!-- bootstrap-table 表格插件 -->
<script src="${basePath }/static/ajax/libs/bootstrap-table/bootstrap-table.min.js"></script>
<script src="${basePath }/static/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${basePath }/static/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js"></script>
<script src="${basePath }/static/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js"></script>
<script src="${basePath }/static/ajax/libs/bootstrap-table/extensions/columns/bootstrap-table-fixed-columns.js"></script>
<!-- jquery-validate 表单验证插件 -->
<script src="${basePath }/static/ajax/libs/validate/jquery.validate.min.js"></script>
<script src="${basePath }/static/ajax/libs/validate/messages_zh.min.js"></script>
<script src="${basePath }/static/ajax/libs/validate/jquery.validate.extend.js"></script>
<!-- jquery-validate 表单树插件 -->
<script src="${basePath }/static/ajax/libs/bootstrap-treetable/bootstrap-treetable.js"></script>
<!-- jquery-export 表格导出插件 -->
<script src="${basePath }/static/ajax/libs/bootstrap-table/extensions/export/bootstrap-table-export.js"></script>
<script src="${basePath }/static/ajax/libs/bootstrap-table/extensions/export/tableExport.js"></script>
<!-- 遮罩层 -->
<script src="${basePath }/static/ajax/libs/blockUI/jquery.blockUI.js"></script>
<script src="${basePath }/static/ajax/libs/iCheck/icheck.min.js"></script>
<script src="${basePath }/static/ajax/libs/layer/layer.min.js"></script>
<script src="${basePath }/static/ajax/libs/layui/layui.js"></script>
<script src="${basePath }/static/ruoyi/js/common.js"></script>
<script src="${basePath }/static/ruoyi/js/ry-ui.js"></script>
<script src="${basePath }/static/ajax/libs/jquery-layout/jquery.layout-latest.js"></script>

<script>

    $(".user_detial").click(function () {
    	let id = $(this).attr("data-id");  	
    	
    	var url = rootPath + "/system/user/detial.do?userId="+id; 
        $.modal.open("用户详情", url);
    });
    
    $(".user_fraze").click(function(){
		let email = $(this).attr("data-id");  	
		$.modal.confirm("确认要取消冻结当前用户吗？", function() {
			$.ajax({
	        	url:rootPath + "/update/user/status.do?status=0&&email="+email,
	        	type:"GET",
	        	dataType : "json",
	            success : function (response) {
	            	layer.msg(response.message, {
	            	    icon: 1,
	            	    time: 2000,
	            	    shade: [0.1, '#8F8F8F']
	            	},function() {
	            		location.reload();
	            	});
	            }                	  
	        });
		});
    });
   

  	//获取项目根目录
	function getRootPath(){
		let href = window.document.location.href;
		let pathName = window.document.location.pathname;
		let index = href.indexOf(pathName);
		let localhost = href.substring(0,index);
		let project = pathName.substring(0,(pathName.substr(1).indexOf('/'))+1);
			
		return (localhost+project);
	}
	
	var rootPath = getRootPath();
    
</script>
</body>
</html>